package com.cj.search.controller;

import com.cj.common.dto.PageDTO;
import com.cj.search.pojo.ItemDoc;
import com.cj.search.pojo.RequestParams;
import com.cj.search.service.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Hasee
 * @version 1.0
 * @description: TODO
 * @date 2023/3/18 15:52
 */
@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private ISearchService searchService;

    @GetMapping("/suggestion")
    public List<String> getSuggestion(@RequestParam("key")String prefix){

        System.out.println(prefix);
        List<String> suggestion = searchService.getSuggestion(prefix);
        return suggestion;
    }

    @PostMapping("/filters")
    public Map<String,List<String>> filter(@RequestBody RequestParams requestParams){

        return searchService.filter(requestParams);
    }

    @PostMapping("/list")
    public PageDTO<ItemDoc> list(@RequestBody RequestParams requestParams){
        PageDTO<ItemDoc> pageDTO =  searchService.list(requestParams);
        return pageDTO;
    }
}
